<template>
  <div :style="{ height: nowheight, width: nowwidth }">
    <Echart
      v-if="chartstau"
      :options="options"
      :style="{ height: '100%', width: '100%' }"
    />
  </div>
</template>

<script>
import Echart from "../../baseMain/index.vue";
export default {
  components: {
    Echart
  },
  props: {
    nowwidth: {
      type: String,
      default: () => "600px"
    },
    nowheight: {
      type: String,
      default: () => "300px"
    },
    cdata: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      chartstau: true,
      options: {}
    };
  },
  watch: {
    cdata: {
      handler(newData) {
        this.$nextTick(() => {
          this.options = {
            tooltip: {},
            color: ["#2CD1E4"],
            xAxis: {
              data: newData.xAxisdata,
              // 让x轴的字体倾斜
              axisLabel: {
                rotate: newData.font
              },
              axisLine: {
                lineStyle: {
                  color: "#fff"
                }
              },
              splitLine: {
                show: false,
                lineStyle: {
                  color: "#ffffff8a"
                }
              },
              axisTick: {
                show: true
              }
            },
            yAxis: {
              type: "value",
              axisLine: {
                show: false,
                lineStyle: {
                  color: "#fff"
                }
              },
              splitLine: {
                show: true,
                lineStyle: {
                  color: "#ffffff8a"
                }
              }
            },
            series: newData.seriesData,
            grid: {
              x: 30,
              y: 60,
              x2: 50,
              y2: 75
            }
          };
        });
      },
      immediate: true,
      deep: true
    },
    // 应为最内层的高度固定为百分之百，所以写这里
    nowheight: {
      handler(e) {
        this.nowheights = e;
        this.resetsty();
      },
      deep: true
    },
    nowwidth: {
      handler(e) {
        this.nowwidth = e;
        this.resetsty();
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    // 重置样式
    resetsty() {
      this.chartstau = false;
      this.$nextTick(() => {
        this.chartstau = true;
      });
    }
  }
};
</script>

<style lang="scss" scoped></style>
